//
//  HJTabBarController.swift
//  sinaWeibo
//
//  Created by hjun on 16/3/20.
//  Copyright © 2016年 hjun. All rights reserved.
//

import UIKit

class HJTabBarController: UITabBarController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        //使用KVC设置自定义的tabbar
        
        self.setValue(HJMainTabBar(), forKey: "tabBar")
        
        
       addchildviewControllers()
        
        
        
    }
    
    
    func addchildviewControllers(){
        
        /// 首页
        let HomeVC = HomeViewController()
        
        addChildViewController(HomeVC,title:"首页",imageName:"tabbar_home")
        
        //消息
        let MessageVC = MessageViewController()
        
        addChildViewController(MessageVC, title: "消息", imageName: "tabbar_message_center")
        
        
        
        //发现
        let DiscoverVC = DiscoverViewController()
        
        addChildViewController(DiscoverVC, title: "发现", imageName: "tabbar_discover")
        
        //我
        let ProfileVC = ProfileViewController()
        
        addChildViewController(ProfileVC, title: "我", imageName: "tabbar_profile")
        
    }
    
    
    func addChildViewController(Controller: UIViewController,title: String, imageName: String) {
        
        Controller.title = title;
        
        /**
        *  设置普通图片
        */
        Controller.tabBarItem.image = UIImage(named: imageName)
        
        /**
         *  设置高亮图片
         */
        
        
        let imageHighLight = imageName + "_highlighted"
        
        
        
        Controller.tabBarItem.selectedImage = UIImage(named: imageHighLight)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        Controller.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orangeColor()], forState: UIControlState.Selected)
        
        //添加子控制器
        
        addChildViewController(UINavigationController(rootViewController: Controller))
        
        
        
    }
    
    
}
